#include<stdio.h>
#include<stdlib.h>

int Search(int len, int *a);

int main(){
	//get the number of arrays
	int T = 0;
	scanf("%d",&T);
	//the array to store the answers
	int *b = NULL;
	b = (int *)malloc(T * sizeof(int));
	//the loop for T times
	int t = 0;
	for(t = 0; t < T; t++){
		//get the length
		int len = 0;
		scanf("%d",&len);
		//get the array
		int i = 0;
		int *a = NULL;
		a = (int *)malloc(len * sizeof(int));
		for (i = 0; i < len; i++){
			scanf("%d",a+i);
		}
		*(b+t) = Search(len,a);
	}

	for(t = 0; t < T; t++){
		printf("%d\n",*(b + t));
	}

	return 0;
}

int Search(int len, int *a){
	int low = 0;
	int high = len-1;
	//consider that if ai>i,then for every j>i, we have aj>j
	while(low < high){

		int mid = (low + high)/2;

		if (*(a + mid) > mid)
			high = mid;
		else if (*(a + mid) < mid)
			low = mid;
		else if (*(a + mid) == mid)
			return mid;//return the index number
	}
	return -1;//not found
}
